package com.youku.plugins.toolboxV4.view
{
   import fl.controls.RadioButton;
   import com.youku.interfaces.ISkinChangeCompent;
   import flash.display.Sprite;
   import com.youku.baseUI.YoukuTextField;
   import flash.filters.ColorMatrixFilter;
   import com.youku.skin.PartenerSkinManager;
   import flash.text.TextField;
   import flash.text.TextFormat;
   import com.youku.PlayerConfig;
   import com.youku.utils.AssetUtil;
   import flash.text.TextFieldAutoSize;
   
   public class ToolBoxRadioButton extends RadioButton implements ISkinChangeCompent
   {
      
      public function ToolBoxRadioButton() {
         super();
         this._rbwidth = WIDTH;
         this._rbheight = HEIGHT;
         this._hoffset = 0;
         this._voffset = 0;
         this._isDivSkin = false;
         this._textField = AssetUtil.getYoukuTextField(false);
         this._textField.autoSize = TextFieldAutoSize.LEFT;
         this.addChild(this._textField);
         this._background = new Sprite();
         this._background.graphics.beginFill(16777215);
         this._background.graphics.drawRect(0,0,this._rbwidth,this._rbheight);
         this._background.graphics.endFill();
         this._background.visible = false;
         this._selectBackground = new Sprite();
         this._selectBackground.graphics.beginFill(436193);
         this._selectBackground.graphics.drawRect(0,0,this._rbwidth,this._rbheight);
         this._selectBackground.graphics.endFill();
         setStyle("upIcon",this._background);
         setStyle("downIcon",this._background);
         setStyle("overIcon",this._background);
         setStyle("disabledIcon",this._background);
         setStyle("selectedUpIcon",this._selectBackground);
         setStyle("selectedDownIcon",this._selectBackground);
         setStyle("selectedOverIcon",this._selectBackground);
         setStyle("selectedDisabledIcon",this._selectBackground);
         this.buttonMode = true;
         this.useHandCursor = true;
         PartenerSkinManager.push(this);
         this.layout();
      }
      
      private static const WIDTH:Number = 80;
      
      private static const HEIGHT:Number = 30;
      
      private var _rbwidth:Number;
      
      private var _rbheight:Number;
      
      private var _hoffset:Number;
      
      private var _voffset:Number;
      
      private var _fontHoffset:Number;
      
      private var _background:Sprite;
      
      private var _selectBackground:Sprite;
      
      private var _textField:YoukuTextField;
      
      private var _isDivSkin:Boolean;
      
      public function setWH(param1:Number, param2:Number) : void {
         this._rbwidth = param1;
         this._rbheight = param2;
         this.layout();
      }
      
      public function get text() : String {
         return this._textField.text;
      }
      
      public function set text(param1:String) : void {
         this._textField.text = param1;
      }
      
      override public function set selected(param1:Boolean) : void {
         var _loc3_:ColorMatrixFilter = null;
         if(!enabled)
         {
            return;
         }
         super.selected = param1;
         var _loc2_:Array = [];
         if(this._isDivSkin)
         {
            _loc2_ = PartenerSkinManager.getFilters(PartenerSkinManager.SETUP_TXT);
         }
         else
         {
            _loc3_ = new ColorMatrixFilter([0,0,0,0,34,0,0,0,0,34,0,0,0,0,34,0,0,0,1,1]);
            _loc2_.push(_loc3_);
         }
         if((this.group) && (this.group.selection) && this.group.selection.value == this.value)
         {
            this._textField.filters = _loc2_;
         }
         else
         {
            this._textField.filters = [];
         }
      }
      
      override public function set enabled(param1:Boolean) : void {
         super.enabled = param1;
         var _loc2_:ColorMatrixFilter = new ColorMatrixFilter([0,0,0,0,85,0,0,0,0,85,0,0,0,0,85,0,0,0,1,1]);
         if(param1)
         {
            this._textField.filters = [];
         }
         else
         {
            this._textField.filters = [_loc2_];
         }
      }
      
      public function get costomTextField() : TextField {
         return this._textField;
      }
      
      public function set costomTextFormat(param1:TextFormat) : void {
         this._textField.defaultTextFormat = param1;
      }
      
      override public function get width() : Number {
         return this._rbwidth;
      }
      
      override public function get height() : Number {
         return this._rbheight;
      }
      
      public function set hoffset(param1:Number) : void {
         this._hoffset = param1;
         this.layout();
      }
      
      public function set voffset(param1:Number) : void {
         this._voffset = param1;
         this.layout();
      }
      
      public function set fontHoffset(param1:Number) : void {
         this._textField.fontHoffset = param1;
      }
      
      private function layout() : void {
         this._background.width = this._selectBackground.width = this._rbwidth;
         this._background.height = this._selectBackground.height = this._rbheight;
         this._textField.x = int((this._rbwidth - this._textField.textWidth) / 2) + 3 + this._voffset;
         this._textField.y = 4 + this._hoffset;
      }
      
      public function upDateSkin() : void {
         if(PlayerConfig.rootData.styleid < 2)
         {
            return;
         }
         if(PlayerConfig.partnerData.skinData.status == 0 || !PlayerConfig.partnerData.skinData.isSetupDiv)
         {
            return;
         }
         this._isDivSkin = true;
         this._selectBackground.filters = PartenerSkinManager.getFilters(PartenerSkinManager.SETUP_BTN);
      }
      
      public function clearSkin() : void {
         this._isDivSkin = false;
         this._selectBackground.filters = [];
      }
   }
}
